<template>
	<div class="search">
		<div class="wrapper">
			<input class="input" type="text" :placeholder="placeholder" v-model="text" />
			<div class="button" @click="onClick"><i id="icon" class="el-icon-search"></i></div>
		</div>
	</div>
</template>

<script>
export default {
	data() {
		return {
			text: ''
		};
	},
	props: {
		placeholder: { type: String, default: '' }
	},
	methods: {
		onClick() {
			this.$emit('searchClick', this.text);
		}
	},
	watch: {
		text() {
			this.$emit('textChange', this.text);
		}
	}
};
</script>

<style lang="less" scoped="scoped">
.wrapper {
	display: inline-block;
	border: 1px solid #24bcb8;
	border-radius: 30px;
	width: auto;
	height: 32px;
	overflow: hidden;
	transition: all 1s linear;
}
.wrapper .input {
	display: inline-block;
	float: left;
	border-radius: 30px;
	height: 30px;
	border: none;
	outline: none;
	width: 0px;
	font-size: 10px;
	transition: all 1s linear;
}
.wrapper:hover .input, .wrapper .input:focus, .wrapper .input:not(:placeholder-shown) {
	width: 140px;
	padding: 0 5px;
}
.wrapper .button {
	display: inline-block;
	float: right;
	height: 30px;
	width: 30px;
	cursor: pointer;
	border-radius: 30px;
	text-align: center;
	transition: all 1s linear;
}
.wrapper .button #icon {
	line-height: 30px;
	width: 30px;
	height: 30px;
	font-size: 18px;
	float: right;
	background-color: #24bcb8;
	color: white;
	transition: all 1s linear;
}
.wrapper .input:focus + .button #icon, .wrapper .input:not(:placeholder-shown) + .button #icon {
	width: 50px;
}
.wrapper:hover .button #icon {
	width: 50px;
}
</style>
